package NW_MC;

import NWPackage.Cell;

public class Huristics {

	/*Lihi's addition, instead of entropy it returns the highest probability*/
	public static double MyopicWinner(Cell assumption, MCEntropyMatrix winnersStatistics,double assumptionProbability) throws Exception{
		boolean containWinner = true;
		if (assumption!=null)
			containWinner = winnersStatistics.isContainWinner(assumption);
	//	else
		//	throw new Exception ("Exception in class Huristics: assumption is null");
		if (containWinner)  //return the winner prob
			return winnersStatistics.calcProbability(assumptionProbability) ;
		else
			return Double.NEGATIVE_INFINITY;
	}
	
	
	public static double Myopic(Cell assumption, MCEntropyMatrix winnersStatistics,double assumptionProbability){		 
		return winnersStatistics.calcProbability(assumptionProbability) ;		 
	}
	
	public static double PureWinner(Cell assumption, MCEntropyMatrix winnersStatistics,double assumptionProbability) throws Exception{	
		boolean containWinner = true;
		if (assumption!=null)
			containWinner = winnersStatistics.isContainWinner(assumption);
		//else
			//throw new Exception ("Exception in class Huristics: assumption is null");
		if (containWinner)  //return the winner prob
			return 1;
		else
			return 0;
	}
	
	public static double PurePreferredWinner(Cell assumption, MCEntropyMatrix winnersStatistics,double assumptionProbability) throws Exception{	
		boolean containWinner = true;
		if (assumption!=null)
			containWinner = winnersStatistics.isContainPreferredWinner(assumption);
		//else
			//throw new Exception ("Exception in class Huristics: assumption is null");
		if (containWinner)  //return the winner prob
			return 1;
		else
			return 0;
	}
	
	public static double AllWinners(Cell assumption, MCEntropyMatrix winnersStatistics, double assumptionProbability,  double fullEntropy) throws Exception
	{
		//check if assumption cell contains the winner (by statistics)
		boolean containWinner = true;
		if (assumption!=null){
			containWinner = winnersStatistics.isContainWinner(assumption);
		//	System.out.println("not null");
		//	System.out.println("Huristics: W= " +winnersStatistics.getWinner() + " v=" +assumption.getAgentName()+ " c's=" + assumption.getAlgPrefferedCandidate());
		}
		//else{ //not intresting - this happens when calculating full entropy a1st iteration - assumption is null!!
			//System.out.println ("Exception in class Huristics: assumption is null");			
		//}						
		
	//	System.out.println("I'm here, calculating");	
		if (containWinner)
			return winnersStatistics.calcWeightedEntropy(assumptionProbability,fullEntropy);
		else
			return Double.NEGATIVE_INFINITY;
		
	}


	public static double WinnerVSLoser(Cell assumption,	MCEntropyMatrix winnersStatistics, double assumptionProbability,double fullEntropy) throws Exception {
		boolean containWinner = true;
		boolean containLoser = true;
		if (assumption!=null){
			containWinner = winnersStatistics.isContainWinner(assumption);		
			if (containWinner){
				containLoser = winnersStatistics.isContainLoser(assumption);
				if (containLoser)
					return winnersStatistics.calcWeightedEntropy(assumptionProbability,fullEntropy); 
			}
		}
		return Double.NEGATIVE_INFINITY;
	}


	public static double allQueries(MCEntropyMatrix winnersStatistics, double assumptionProbability,double fullEntropy) throws Exception {
		return winnersStatistics.calcWeightedEntropy(assumptionProbability,fullEntropy);
	}


	public static double WinnerVSSecond(Cell assumption, MCEntropyMatrix winnersStatistics, double assumptionProbability, double fullEntropy) throws Exception {
		boolean containWinner = true;
		boolean containSecond = true;
		if (assumption!=null){
			containWinner = winnersStatistics.isContainWinner(assumption);
			if (containWinner){
				containSecond = winnersStatistics.isContainSecondWinner(assumption);
				if (containSecond)
					return winnersStatistics.calcWeightedEntropy(assumptionProbability,fullEntropy); 
			}
		}
		return Double.NEGATIVE_INFINITY;
	}
	
}
